import GameConfig from "../config/GameConfig.js";
import Rect from "./Rect.js";
import RectType from "./RectType.js";

export default class MapRect extends Rect {
    // f = g + h
    public f: number = 0
    public g: number = 0
    public h: number = 0
    public type: RectType = RectType.Ground
    public parent: MapRect | null = null
    constructor(x: number = 0, y: number = 0, width: number = GameConfig.RectSize, height: number = GameConfig.RectSize) {
        super(x, y, width, height)
    }
    draw(context: CanvasRenderingContext2D | null) {
        if (!context) return
        // context.fillStyle = this.type == RectType.Ground ? 'green' : '#f52'
        switch (this.type) {
            case RectType.Border:
                context.fillStyle = GameConfig.TileColor.Border
                break
            case RectType.Ground:
                context.fillStyle = GameConfig.TileColor.Ground
                break
            case RectType.Obstacles:
                context.fillStyle = GameConfig.TileColor.Obstacles
                break
        }
        context.fillRect(this.x * this.width + 1, this.y * this.height + 1, this.width - 1, this.height - 1)
        context.strokeStyle = '#999'
        context.font = '16px 宋体'
        context.strokeText(`(${this.x},${this.y})`, this.x * this.width + 2, this.y * this.height + 14)
    }
}